package com.huawei.appmarket.service.webview.js;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings.TextSize;
import android.webkit.WebView;
import com.huawei.appgallery.search.api.ISearchActivityProtocol;
import o.azt;
import o.azw;
import o.cjk;
import o.cjm;
import o.der.c;
import o.Logger;
import o.enm;
import o.enr;
import o.ens;
import o.epr;
import o.erz;
import o.evk;
import o.ezn;
import o.fbk;
import o.fbp;
import o.fho;
import o.fiu;
import o.fjb;

public class ExtraJsObject implements fbp, azw {
    private static final String TAG = "ExtraJsObject";
    private boolean isFromBuoy = false;
    protected Context mContext = null;
    protected final Handler mHandler = new Handler(Looper.getMainLooper());
    protected azt mJsCallBack = null;
    protected WebView mWebView = null;
    private String packageName;

    public ExtraJsObject(Context context, azt o_azt, WebView webView) {
        this.mContext = context;
        this.mJsCallBack = o_azt;
        this.mWebView = webView;
    }

    public String getPackageName() {
        return this.packageName;
    }

    public void setPackageName(String str) {
        this.packageName = str;
    }

    public void setFromBuoy(boolean z) {
        this.isFromBuoy = z;
    }

    public void setWebView(WebView webView) {
        this.mWebView = webView;
        if (this.mContext == null || this.mWebView != null) {
            this.mContext = this.mWebView.getContext();
        }
    }

    @JavascriptInterface
    public void openH5Game(String str) {
        fbk.ॱ(this.mContext, str);
    }

    @JavascriptInterface
    public void setTextSizeNormal() {
        if (this.mWebView != null) {
            this.mWebView.post(new Runnable(this) {
                final /* synthetic */ ExtraJsObject ˏ;

                {
                    this.ˏ = r1;
                }

                public void run() {
                    this.ˏ.mWebView.getSettings().setTextSize(TextSize.NORMAL);
                }
            });
        }
    }

    @JavascriptInterface
    public void enter() {
        if (this.mContext instanceof Activity) {
            Activity activity = (Activity) this.mContext;
            cjk.ˎ().ˋ(activity, new cjm("market.activity", null));
            activity.overridePendingTransition(c.ˏ, c.ˋ);
            activity.finish();
        }
    }

    @JavascriptInterface
    public void search() {
        fjb ˎ = fho.ˏ().ˋ("Search").ˎ("Search");
        ˎ.ॱ(this.mContext);
        ((ISearchActivityProtocol) ˎ.ˊ()).setFromMain(false);
        Intent intent = null;
        if (!(this.mContext instanceof Activity)) {
            intent = new Intent();
            intent.setFlags(268435456);
        }
        fiu.ˊ().ॱ(this.mContext, ˎ, intent);
    }

    @JavascriptInterface
    public void share(String str) {
        if (this.isFromBuoy) {
            enm.ˊ(this.mContext, this.mHandler, str);
        } else if (this.mJsCallBack != null) {
            ens.ॱ(this.mContext, str, this.mJsCallBack.ˍ(), this.mJsCallBack.ˊᐝ());
        }
    }

    protected void startActivityIfNewTask(Intent intent) {
        if (!(this.mContext instanceof Activity)) {
            intent.setFlags(268435456);
        }
        this.mContext.startActivity(intent);
    }

    @JavascriptInterface
    public void toDetailPage(String str) {
        enr.ˎ(this.mContext, str);
    }

    @JavascriptInterface
    public boolean isInstalled(String str) {
        return erz.ˏ(this.mContext, str);
    }

    @JavascriptInterface
    public boolean isInstalled(String str, int i) {
        Logger.ˏ(TAG, "js: isInstalled packageName:" + str + ", version:" + i);
        if (!TextUtils.isEmpty(str) && erz.ˎ(this.mContext, str) >= i) {
            return true;
        }
        return false;
    }

    @JavascriptInterface
    public void refresh() {
        if (this.mJsCallBack != null) {
            this.mHandler.post(new Runnable(this) {
                final /* synthetic */ ExtraJsObject ˊ;

                {
                    this.ˊ = r1;
                }

                public void run() {
                    this.ˊ.mJsCallBack.ˊॱ();
                }
            });
        }
    }

    @JavascriptInterface
    public void goBack() {
        this.mHandler.post(new Runnable(this) {
            final /* synthetic */ ExtraJsObject ॱ;

            {
                this.ॱ = r1;
            }

            public void run() {
                if (this.ॱ.mJsCallBack != null) {
                    this.ॱ.mJsCallBack.ॱˊ();
                }
            }
        });
    }

    @JavascriptInterface
    public void showToast(String str) {
        if (!ens.ॱ(str) || this.mContext == null) {
            Logger.ˋ(TAG, "showToast:fail because of invalid text or mContext is null!");
        } else {
            showToastImpl(str);
        }
    }

    protected void showToastImpl(final String str) {
        this.mHandler.post(new Runnable(this) {
            final /* synthetic */ ExtraJsObject ॱ;

            public void run() {
                if (this.ॱ.mJsCallBack.ˎ(this.ॱ.mWebView)) {
                    ezn.ˊ().ॱ(str, 0);
                } else {
                    evk.ˋ(this.ॱ.mContext, str, 0).ˋ();
                }
            }
        });
    }

    @JavascriptInterface
    public boolean closeWebview() {
        this.mHandler.post(new Runnable(this) {
            final /* synthetic */ ExtraJsObject ˏ;

            {
                this.ˏ = r1;
            }

            public void run() {
                if (this.ˏ.mContext instanceof Activity) {
                    ((Activity) this.ˏ.mContext).finish();
                } else {
                    this.ˏ.mJsCallBack.ॱˊ();
                }
            }
        });
        return true;
    }

    @JavascriptInterface
    public int getDeviceType() {
        return epr.ˎ().ॱॱ() ? 1 : 0;
    }

    @JavascriptInterface
    public void onPageLoaded(String str, String str2) {
        ens.ˏ(this.mContext, str, str2);
    }

    @JavascriptInterface
    public void onPageLoaded(String str, String str2, String str3) {
        ens.ˋ(this.mContext, str, str2, str3);
    }

    @JavascriptInterface
    public void hidenVerticalScroll() {
        if (this.mWebView != null) {
            this.mWebView.setVerticalScrollBarEnabled(false);
        }
    }

    @JavascriptInterface
    public void playVideo(String str, int i) {
        ens.ˊ(this.mContext, str, i);
    }

    @JavascriptInterface
    public void setCampaignForumId(String str) {
        this.mJsCallBack.ॱˊ(str);
    }
}
